package com.jk.myimkit.imkit.widget.provide;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;

import com.jk.myimkit.R;
import com.jk.myimkit.imkit.RongContext;
import com.jk.myimkit.imkit.RongExtension;
import com.jk.myimkit.imkit.RongIM;
import com.jk.myimkit.imkit.plugin.IPluginModule;

import io.rong.imlib.IRongCallback;
import io.rong.imlib.model.Message;
import io.rong.message.LocationMessage;

public class LocationPlugin implements IPluginModule {
    public LocationPlugin() {
    }

    public Drawable obtainDrawable(Context context) {
        return context.getResources().getDrawable(R.drawable.rc_ext_plugin_location_selector);
    }

    public String obtainTitle(Context context) {
        return context.getString(R.string.rc_plugin_location);
    }

    public void onClick(Fragment currentFragment, final RongExtension extension) {
        if (RongContext.getInstance() != null && RongContext.getInstance().getLocationProvider() != null) {
            RongContext.getInstance().getLocationProvider().onStartLocation(currentFragment.getActivity().getApplicationContext(), new RongIM.LocationProvider.LocationCallback() {
                public void onSuccess(LocationMessage locationMessage) {
                    Message message = Message.obtain(extension.getTargetId(), extension.getConversationType(), locationMessage);
                    RongIM.getInstance().sendLocationMessage(message, (String)null, (String)null, (IRongCallback.ISendMessageCallback)null);
                }

                public void onFailure(String msg) {
                }
            });
        }

    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    }
}
